<?php
/**
 * 站点API 系统配置
 */

class NsiteApi extends ApiBase{

	/**
	 * 构造函数，初始化插件
	 */
	public function __construct() {
		parent::__construct();
		$this->db = n_api("mysql")->db001;
		$this->redis = n_api("redis")->c001;
	}

	/**
	 * [获取缓存key]
	 * @param  [type] $fun [description]
	 * @param  [type] $key [description]
	 * @return [type]      [description]
	 */
	public function getCacheKey($fun,$key){
		$fun = strtolower($fun);
		return "nsite:{$fun}:{$key}";
	}

	/**
	 * [根据id获取nsite_main信息]
	 * @param  [int] $id [nsite.id]
	 * @return [array or throw]   [nsite.row]
	 */
	public function get($id){

		$key = $this->getCacheKey('get',$id);
		$row = $this->redis->get($key);

		if (!empty($row)) {
			return json_decode($row,true);
		}
		
		$row = $this->db->fetchFirst("select * from nsite_main where id='{$id}'");
		$this->redis->setex($key,1800,json_encode($row));

		if (empty($row)) {
			throw new Exception("不存在scode={$scode}站点", 1);
		}
		
		return $row;
	}

	/**
	 * [根据scode获取站点信息]
	 * @param  [str] $scode [description]
	 * @return [array or throw]        [description]
	 */
	public function getByScode($scode){
		$key = $this->getCacheKey('getByScode',$scode);
		$row = $this->redis->get($key);
		
		if (!empty($row)) {
			return json_decode($row,true);
		}
		
		$row = $this->db->fetchFirst("select * from nsite_main where scode='{$scode}'");
		$this->redis->setex($key,1800,json_encode($row));
		
		if (empty($row)) {
			throw new Exception("不存在scode={$scode}站点", 1);
		}

		return $row;
	}

	/**
	 * [获取同一内容存储的站点]
	 * @param  [type] $gcode [description]
	 * @return [type]        [description]
	 */
	public function getByGsite($gcode){
		$rs = n_api("mysql")->db001->select("select * from nsite_main where gcode='{$gcode}' and isdel = 'N'");
		if (empty($rs)) {
			throw new Exception("不存在gsite={$gcode}站点", 1);	
		}
		return $rs;
	}

	/**
	 * [获取同一用户存储的站点]
	 * @param  [type] $ucode [description]
	 * @return [type]        [description]
	 */
	public function getByUsite($ucode){
		$rs = n_api("mysql")->db001->select("select * from nsite_main where ucode='{$ucode}' and isdel = 'N'");
		if (empty($rs)) {
			throw new Exception("不存在usite={$ucode}站点", 1);	
		}
		return $rs;
	}

	/**
	 * [根据scode获取gcode]
	 * @param  [str] $scode [description]
	 * @return [str]        [gcode:数据存储位置由gcode决定]
	 */
	public function getGcode($scode){
		try {
			$row = $this->getByScode($scode);
			return $row['gcode'];
		} catch (Exception $e) {
			return false;
		}
	}

	public function getGsite($scode){
		try {
			$row = $this->getByScode($scode);
			return 'content_'.$row['gcode'];
		} catch (Exception $e) {
			return false;
		}
	}
	
	public function getUsite($scode){
		try {
			$row = $this->getByScode($scode);
			return 'user_'.$row['ucode'];
		} catch (Exception $e) {
			return false;
		}
	}

	public function getGinfo($ppid,$code){
		return $this->db->fetchFirst("select * from nsite_gucode where ppid = {$ppid} and type = 'gcode' and isdel = 'N' and code = '{$code}' ");
	}

	public function getUinfo($ppid,$code){
		return $this->db->fetchFirst("select * from nsite_gucode where ppid = {$ppid} and type = 'ucode' and isdel = 'N' and code = '{$code}' ");
	}

	/**
	 * [getGlist gcode列表]
	 * @param  [int] $ppid [description]
	 * @return [arr]       [description]
	 */
	public function getGlist($ppid){
		return $this->db->select("select * from nsite_gucode where ppid = {$ppid} and type = 'gcode' and isdel = 'N' ");
	}

	/**
	 * [getGlist gcode列表]
	 * @param  [int] $ppid [description]
	 * @return [arr]       [description]
	 */
	public function getUlist($ppid){
		return $this->db->select("select * from nsite_gucode where ppid = {$ppid} and type = 'ucode' and isdel = 'N' ");
	}

	/**
	 * [getDefaultGlist gcode列表]
	 * @return [arr]       [description]
	 */
	public function getDefaultGlist(){
		return $this->db->select("select * from nsite_gucode where type = 'gcode' and isdel = 'N' and dstorage = 'Y'");
	}

	/**
	 * [getDefaultGlist gcode列表]
	 * @return [arr]       [description]
	 */
	public function getDefaultUlist(){
		return $this->db->select("select * from nsite_gucode where type = 'ucode' and isdel = 'N' and dstorage = 'Y'");
	}

	public function sign($mkey,$rkey){
		// return md5($mkey.$rkey);
		return md5($mkey.':'.trim($rkey));
	}
	
	/**
	 * 获取当前活跃的网站码。
	 */
	public function getCurrScode(){
		$param = $this->param("scode:char:ignore");
		//linruiyan@2013-6-12 先判断是否有新的scode，如果没有才采用session中的。
		//顺序一定要这样。不然可能导致一个scode进入session后无法更改
		
		if(!empty($param['scode'])){
			$rs = $param['scode'];
			//$_SESSION['scode'] = $rs;
		}elseif(!empty($_SESSION['scode'])){
			$rs = $_SESSION['scode'];
		}else{
			$rs = '';
			//throw new PException("找不到网站码");
		}
		return $rs;
	}
	
	/**
	 * 通过注册的插件查找站点
	 */
	public function getReged($pcode){
		return n_api("mysql")->db001->select("select b.* from nsite_plugins as a
												left join nsite_main as b on a.site_id=b.id
												where pevent='{$pcode}'");
	}

	/**
	 * 查找某个站点注册的插件
	 */
	public function getSiteReged($site){
		$reged = n_api("mysql")->db001->select("select * from nsite_plugins where site_id={$site}");
		
		$pbox = n_api('pbox')->getList();
		//print_r($pbox);
		$rs = array();
		
		if(!empty($reged)){
			foreach ($reged as $key => $val) {
				$rs[$key] = $pbox[$val['pevent']];
			}
		}
		return $rs;
		
	}
	
	/**
	 * [getList 获取站点列表]
	 * @param  [int] $ppid [创建人id]
	 * @return [arr]       [description]
	 */
	public function getList($ppid=0){
		if ($ppid > 0) {
			$condition = " and ppid = {$ppid}";
		}

		return n_api("mysql")->db001->select("select * from nsite_main where isdel='N' {$condition}");
	}


	public function getMemberSite($ppid){
		if(empty($ppid)){
			throw new PException("找不到用户");
		}
		$site = $this->getList();
		$rs = array();
		if(!empty($site)){
			foreach($site as $key=>$val){
				//linruiyan@2013-6-12 创建网站后，权限处于真空状态。所有加入了所有人概念，对于所有人这里会开放所有的权限
				if(n_api("rbac")->checkPeventOr($ppid,$val['scode'],'nsite') || $ppid==$val['ppid']){
					$rs[$val['id']] = $val;
					//echo $val['scode'].'-------------';
				}
			}
		}
		return $rs;
	}

	public function getPlayer($id){
		$mysql = n_api("mysql")->db001;
		return $mysql->select("select * from nsite_player where main_id={$id}");
	}

	/**
	 * initRule
	 *
	 * 初始化站点规则nconfig配置
	 * 
	 * @param  string $scode 站点代码
	 * 
	 * @return boolean
	 */
	public function initRule($scode) {

		$rules = array(
			array('scode' => $scode, 'pevent' => 'blackeggs', 'ckey' => 'antiallphone', 'descript' => '手机全禁', 'value' => 'false'),
			array('scode' => $scode, 'pevent' => 'blackeggs', 'ckey' => 'antiallqq', 'descript' => 'qq全禁', 'value' => 'false'),
			array('scode' => $scode, 'pevent' => 'blackeggs', 'ckey' => 'antiallurl', 'descript' => 'url全禁', 'value' => 'false'),
			array('scode' => $scode, 'pevent' => 'blackeggs', 'ckey' => 'antiurlcount', 'descript' => '文本中url的限制', 'value' => '10'),
			array('scode' => $scode, 'pevent' => 'blackeggs', 'ckey' => 'garbagelimit', 'descript' => '文本中提取垃圾的限制', 'value' => '10'),
			
			array('scode' => $scode, 'pevent' => 'ectype', 'ckey' => 'clen', 'descript' => '内容长度', 'value' => '30'),
			array('scode' => $scode, 'pevent' => 'ectype', 'ckey' => 'frequency', 'descript' => '内容频率', 'value' => '5'),
			array('scode' => $scode, 'pevent' => 'ectype', 'ckey' => 'timesize', 'descript' => '有效期(秒)', 'value' => '10000'),
			
			array('scode' => $scode, 'pevent' => 'idip', 'ckey' => 'expires', 'descript' => '时间范围:N秒', 'value' => '10'),
			array('scode' => $scode, 'pevent' => 'idip', 'ckey' => 'frequency', 'descript' => 'N秒内发帖量', 'value' => '5'),
			array('scode' => $scode, 'pevent' => 'idip', 'ckey' => 'id_autolock_frequency', 'descript' => 'ID自动禁言次数', 'value' => '10'),
			array('scode' => $scode, 'pevent' => 'idip', 'ckey' => 'id_autolock_time', 'descript' => 'ID自动禁言时长', 'value' => '3600'),
			array('scode' => $scode, 'pevent' => 'idip', 'ckey' => 'ip_autolock_frequency', 'descript' => 'IP自动禁言次数', 'value' => '10'),
			array('scode' => $scode, 'pevent' => 'idip', 'ckey' => 'ip_autolock_time', 'descript' => 'IP自动禁言时长', 'value' => '3600'),
			
			array('scode' => $scode, 'pevent' => 'semantic', 'ckey' => 'semantic_num', 'descript' => '相似文章删除值', 'value' => '4'),
		);

		$oNconfig = n_api('nconfig');
		foreach ($rules as $key => $v) {
			$oNconfig->addSite($v);
		}

		return true;

	}

	/**
	 * [初始化规则]
	 * @param  [type] $scode [description]
	 * @return [type]        [description]
	 */
	public function initNrule($scode){
		$enableList = n_api('nrule')->getEnableList();

		if (!empty($enableList)) {
			foreach ($enableList as $k => $v) {
				$this->setFilterAnrule($scode,$v['nr_key'],array(),$v['enable']);
			}
		}
	}

	/**
	 * [initDB 创建存储]
	 * @param  [str] $code [$code in ($gcode,$ucode) ]
	 * @return [type]       [description]
	 */
	public function initDBcontent($code){
		$db001 = n_api("mysql")->db001;
		$demo_db = "content_demo";
		$db001->exec("use {$demo_db}");

		//多台服务器时 需要指点创建mysql位置 目前只有site3307
		$site3307 = n_api("mysql")->site2;
		
		//创建内容存储
		$des_db = "content_{$code}";
		$site3307->exec("CREATE DATABASE `{$des_db}`CHARACTER SET utf8 COLLATE utf8_general_ci");
		$site3307->exec("use {$des_db}");
		$tables = array(
						"content_data",
						"content_ext",
						"content_main",
						"content_pic",
						"content_pplog",
						"content_token"
						);
		foreach($tables as $key=>$val){
			$tinfo = $db001->select("SHOW CREATE TABLE `{$val}`");
			$site3307->exec($tinfo[0]['Create Table']);
		}
	}

	public function initDBuser($code){
		$db001 = n_api("mysql")->db001;
		$demo_db = "user_demo";
		$db001->exec("use {$demo_db}");

		//多台服务器时 需要指点创建mysql位置 目前只有userdb
		$userdb = n_api("mysql")->userdb;
		
		//创建内容存储
		$des_db = "user_{$code}";
		$userdb->exec("CREATE DATABASE `{$des_db}`CHARACTER SET utf8 COLLATE utf8_general_ci");
		$userdb->exec("use {$des_db}");
		$tables =array(
						"user_id_main",
						"user_ip_main"
				);
		foreach($tables as $key=>$val){
			$tinfo = $db001->select("SHOW CREATE TABLE `{$val}`");
			$userdb->exec($tinfo[0]['Create Table']);
		}
	}

	/**
	 * [isExistFilterRule 验证站点是否添加规则]
	 * @param  [str]  $scode  [站点scode]
	 * @param  [str]  $pevent [规则pevent]
	 * @return [arr]          [description]
	 */
	public function isExistFilterRule($scode,$pevent){
		return $row = $this->db->fetchFirst("select * from nsite_nrule where scode='{$scode}' and nr_key = '{$pevent}'");
	}

	/**
	 * [getFilterNrule 获取站点过滤的规则信息]
	 * @param  [str] $scode  [description]
	 * @param  [str] $pevent [规则插件名]
	 * @return [arr]         []
	 */
	public function getFilterNrule($scode,$pevent){
		if (empty($scode) || empty($pevent)) {
			throw new Exception("参数不能为空1", 1);
		}

		$nsiteInfo = $this->getByScode($scode);

		$key = $this->getCacheKey('setFilterNrule',$nsiteInfo['scode'] .':'. $pevent);
		$fnrule = $this->redis->get($key);
		$rs = array();
		
		if ($fnrule == '') {
			$row = $this->db->fetchFirst("select * from nsite_nrule where scode='{$scode}' and nr_key = '{$pevent}'");
			if ($row['rule_rs'] != '') {
				$this->redis->set($key,$row['rule_rs']);
				$fnrule = $row['rule_rs'];
			}
		}

		if ($fnrule != '') {
			$rs = explode(',', $fnrule);
		}

		return $rs;
	}

	/**
	 * [setFilterNrule 设置站点过滤的规则信息]
	 * @param  [str] $scode  [description]
	 * @param  [str] $pevent [规则插件名]
	 * @param  [arr] $data   [规则id]
	 * @param  [str] $opt    [opt=(a添加,d=删除)]
	 * @return [arr]         [arr.state,arr.msg]
	 */
	public function setFilterNrule($scode,$pevent,$data,$opt='a'){
		if (empty($scode) || empty($pevent)) {
			throw new Exception("参数不能为空2", 1);
		}

		if (!in_array(strtolower($opt), array('a','d'))) {
			throw new Exception("参数opt=$opt,错误！opt in (a,d)", 1);
		}

		$nsiteInfo = $this->getByScode($scode);//验证站点是否存在

		$row = $this->db->fetchFirst("select * from nsite_nrule where scode='{$scode}' and nr_key = '{$pevent}'");
		
		$fnrule = empty($data)?'':implode(',', $data);
		
		if (!empty($row)) {
			if (strtolower($opt) == 'a') {//添加取并集
				$tmp['rule_rs'] = empty($row['rule_rs'])?$fnrule:implode(',',array_unique(array_merge(explode(',', $row['rule_rs']),$data)));
			}else{//删除取差集
				$tmp['rule_rs'] = empty($row['rule_rs'])?'':implode(',',array_diff(explode(',', $row['rule_rs']), $data));
			}
			$tmp['utime'] = time();
			$fnrule = $tmp['rule_rs'];

			$this->db->update('nsite_nrule',$tmp," id = {$row['id']}");
		}else{
			$tmp['scode'] = $scode;
			$tmp['nr_key'] = $pevent;
			$tmp['rule_rs'] = $fnrule;
			$tmp['ctime'] = time();
			$tmp['utime'] = $tmp['ctime'];

			$this->db->insert('nsite_nrule',$tmp);
		}
		
		$cacheKey = $this->getCacheKey('setFilterNrule',$nsiteInfo['scode'] .':'. $pevent);
		$this->redis->set($cacheKey,$fnrule);

		return n_state(true,'设置成功');
	}

	/**
	 * [setFilterAnrule 设置站点可使用的过滤规则]
	 * @param [str]  $scode  [站点scode]
	 * @param [str]  $pevent [规则pevent]
	 * @param [arr]  $data   [规则数组]
	 * @param [boa]  $enable [是否开启应用]
	 */
	public function setFilterAnrule($scode,$pevent,$data,$enable='N'){
		if (empty($scode) || empty($pevent)) {
			throw new Exception("参数不能为空scode={$scode},pevent={$pevent}", 1);
		}

		$nsiteInfo = $this->getByScode($scode);//验证站点是否存在

		$row = $this->db->fetchFirst("select * from nsite_nrule where scode='{$scode}' and nr_key = '{$pevent}'");
		
		$fnrule = implode(',', $data);
		
		if (!empty($row)) {
			$tmp['arule_rs'] = empty($row['arule_rs'])?$fnrule:implode(',', array_unique(explode(',', $row['arule_rs'] .','. $fnrule)));
			$tmp['utime'] = time();

			$this->db->update('nsite_nrule',$tmp," id = {$row['id']}");
		}else{
			$tmp['scode'] = $scode;
			$tmp['nr_key'] = $pevent;
			if ($enable === 'Y') {
				$tmp['rule_rs'] = $fnrule;
			}
			$tmp['arule_rs'] = $fnrule;
			$tmp['ctime'] = time();
			$tmp['utime'] = $tmp['ctime'];

			$this->db->insert('nsite_nrule',$tmp);
		}
	}

	/**
	 * [getFilterAnrule 获取站点可使用的过滤规则]
	 * @param  [str] $scode  [站点scode]
	 * @param  [str] $pevent [规则pevent]
	 * @return [arr]         [description]
	 */
	public function getFilterAnrule($scode,$pevent){
		if (empty($scode) || empty($pevent)) {
			throw new Exception("参数不能为空", 1);
		}

		$nsiteInfo = $this->getByScode($scode);//验证站点是否存在
		$sql = "select * from nsite_nrule where scode='{$scode}' and nr_key = '{$pevent}'";
		$row = $this->db->fetchFirst($sql);

		if (empty($row['arule_rs'])) {
			return array();
		}

		$fnrule = explode(',', $row['arule_rs']);

		return $fnrule;
	}

	/**
	 * [获取站点过滤规则]
	 * @param  [str] $scode [description]
	 * @return [arr]        [isset(arr['pevent'])]
	 */
	public function getFilterNruleEnable($scode){
		
		$cacheKey = $this->getCacheKey('setFilterNruleEnable',$scode);
		
		$tmp = array();
		
		if (!$this->redis->EXISTS($cacheKey)) {
			
			$sql = "select * from nsite_nrule where scode = '{$scode}' and isdel = 'N'";
			
			$data = $this->db->select($sql);

			if (!empty($data)) {
				foreach ($data as $k => $v) {
					$tmp[$v['nr_key']] = 'N';
				}
				
				$this->redis->hmSave($cacheKey,$tmp);
			}
		}else{

			$tmp = $this->redis->hmGetAll($cacheKey);

		}

		return $tmp;
	}

	/**
	 * [删除站点过滤规则缓存]
	 * @param  [type] $scode [description]
	 * @return [type]        [description]
	 */
	public function unsetNruleEnable($scode){
		$cacheKey = $this->getCacheKey('setFilterNruleEnable',$scode);
		$this->redis->del($cacheKey);
	}

	/**
	 * [delCheKey description]
	 * @param  [type] $cacheKey [description]
	 * @return [type]           [description]
	 */
	public function delCheKey($cacheKey){
		$this->redis->del($cacheKey);
	}

	/**
	 * [setFilterNrule 设置站点可管理（读、写)的规则信息]
	 * @param  [str] $scode  [description]
	 * @param  [str] $pevent [规则插件名]
	 * @param  [arr] $data   [规则id]
	 * @param  [str] $opt    [opt=(a添加,d=删除)]
	 * @return [arr]         [arr.state,arr.msg]
	 */
	public function setRWNrule($scode,$pevent,$data,$opt='a'){
		if (empty($scode) || empty($pevent) || empty($data)) {
			throw new Exception("参数不能为空2", 1);
		}

		if (!in_array(strtolower($opt), array('a','d'))) {
			throw new Exception("参数opt=$opt,错误！opt in (a,d)", 1);
		}

		$nsiteInfo = $this->getByScode($scode);//验证站点是否存在

		$row = $this->db->fetchFirst("select * from nsite_nrule where scode='{$scode}'  and nr_key = '{$pevent}'");
		
		$fnrule = empty($data)?'':implode(',', $data);

		
		if (!empty($row)) {
			if (strtolower($opt) == 'a') {//添加取并集
				$tmp['rule_rw'] = empty($row['rule_rw'])?$fnrule:implode(',',array_unique(array_merge(explode(',', $row['rule_rw']),$data)));
			}else{//删除取差集
				$tmp['rule_rw'] = empty($row['rule_rw'])?'':implode(',',array_diff(explode(',', $row['rule_rw']), $data));
			}
			$tmp['utime'] = time();
			
			$fnrule = $tmp['rule_rw'];

			$this->db->update('nsite_nrule',$tmp," id = {$row['id']}");
		}else{
			$tmp['scode'] = $scode;
			$tmp['nr_key'] = $pevent;
			$tmp['rule_rw'] = $fnrule;
			$tmp['ctime'] = time();
			$tmp['utime'] = $tmp['ctime'];

			$this->db->insert('nsite_nrule',$tmp);
		}
		
		$cacheKey = $this->getCacheKey('setRWNrule',$nsiteInfo['scode'] .':'. $pevent);
		$this->redis->set($cacheKey,$fnrule);

		return n_state(true,'设置成功');
	}

	/**
	 * [getFilterNrule 获取站点可管理(读、写)的规则信息]
	 * @param  [str] $scode  	[description]
	 * @param  [str] $pevent 	[规则插件名]
	 * @return [arr]         []
	 */
	public function getRWNrule($scode,$pevent){
		if (empty($scode) || empty($pevent)) {
			throw new Exception("参数不能为空1", 1);
		}

		$nsiteInfo = $this->getByScode($scode);

		$key = $this->getCacheKey('setRWNrule',$nsiteInfo['scode'] .':'. $pevent);
		$fnrule = $this->redis->get($key);
		$rs = array();
		
		if ($fnrule == '') {
			$row = $this->db->fetchFirst("select * from nsite_nrule where scode='{$scode}' and nr_key = '{$pevent}'");
			if ($row['rule_rw'] != '') {
				$this->redis->set($key,$row['rule_rw']);
				$fnrule = $row['rule_rw'];
			}
		}

		if ($fnrule != '') {
			$rs = explode(',', $fnrule);
		}

		return $rs;
	}

	public function getMySite($ppid) {
		$mysql = n_api("mysql")->db001;
		$rs['my'] = $mysql->selectIndex("select * from nsite_main where ppid={$ppid} and isdel='N'");
		$rs['join'] = $mysql->selectIndex("select b.* from nsite_player as a left join nsite_main as b on a.main_id=b.id where a.ppid={$ppid} and b.isdel='N'");

		return $rs;
	}

	/**
	 * [getPpidsByScode description]
	 * @param  [string] $scode [description]
	 * @return [array]        [description]
	 */
	public function getPpidsByScode($scode){
		$row = $this->getByScode($scode);
		
		$sql = "SELECT b.ppid FROM nsite_main AS a JOIN nsite_player AS b ON a.id = b.main_id 
			WHERE a.isdel = 'N' AND b.main_id = '{$row['id']}'";
		
		$mysql = n_api("mysql")->db001;
		
		$tmp = $mysql->select($sql);

		$ppids = array($row['ppid']);

		if (!empty($tmp)) {
			foreach ($tmp as $k => $v) {
				array_push($ppids, $v['ppid']);
			}
		}

		return $ppids;
	}


	/**
	 * [获取站点是否答题初始化]
	 * @param  [str] $scode [description]
	 * @return [arr]        [Y/N、throw]
	 */
	public function getInit($scode){
		if (empty($scode)) {
			throw new Exception("参数不能为空1", 1);
		}

		$key = $this->getCacheKey('setInit',$scode);
		$nsiteInit = $this->redis->get($key);

		if (in_array(strtoupper($nsiteInit), array('Y','N'))) {
			return $nsiteInit;
		}
		
		$nsiteInfo = $this->getByScode($scode);

		$this->redis->set($key,$nsiteInfo['isinit']);
		
		return $nsiteInfo['isinit'];
	}

	/**
	 * [站点答题初始化设置]
	 * @param [str] $scode [description]
	 */
	public function setInit($scode){

		$this->getByScode($scode);//站点验证

		$data['isinit'] = 'Y';

		$this->db->update('nsite_main',$data," scode = '{$scode}'");

		$key = $this->getCacheKey('setInit',$scode);

		$this->redis->set($key,$data['isinit']);
	}

	/**
	 * [设置站点是否有余额]
	 * @param [str] $scode [站点scode]
	 * @param [str] $state [状态Y=站点账户有余额，N=站点账户没有余额]
	 */
	public function setState($scode,$state){

		$this->getByScode($scode);//站点验证

		if (!in_array(strtoupper($state), array('Y','N'))) {
			throw new Exception("参数错误state={$state}", 1);
		}

		$data['state'] = strtoupper($state);

		$this->db->update('nsite_main',$data," scode = '{$scode}'");
	}

	/**
	 * [测试站点列表]
	 * @return [type] [description]
	 */
	public function sampleList(){
		return array('c8537e3a50e43bb0');
	}

	/**
	 * [验证站点配置是否可覆盖 只有测试站点配置可以被覆盖]
	 * @param  [str] $scode [description]
	 * @return [boolean]    [true=可覆盖，false=不可覆盖]
	 */
	public function checkNConfReplace($scode){
		$arr = $this->sampleList();
		return in_array($scode, $arr)?true:false;
	}
}

?>